using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFGameFramework;
using XFFSM;
using XFGameFramework.ScriptableObjectSystem;
using XFABManager;

public class Fight : FSMState
{
    
    private Module module ;
    private EnemyController enemyController => module.LoadController<EnemyController>();
    private PlayerController playerController => module.LoadController<PlayerController>();
    private GameController gameController => module.LoadController<GameController>();
    private int enemyId = 1;
    public override void OnEnter()
    {
        base.OnEnter();

        FightInfo.Instance.Rounds = 0;
        FightInfo.Instance.Distance = 6;

        module = userData as Module;
        if (module == null) throw new System.Exception("userData is not Module");

        ScriptableObjectConfigs EnemyConfig = ScriptableObjectManager.GetConfig("EnemyConfig");
        
        EnemyConfigData enemyConfigData = EnemyConfig.GetScriptableObjectData(enemyId) as EnemyConfigData;

        //创建敌人
        enemyController.CreatEnemy(enemyId, enemyConfigData);
        EnemyModel enemy = enemyController.GetEnemyModel();
        module.AddModel(enemy);

        playerController.OnPlayerDead += () =>
        {
            module.LoadPanel<FailPanel>();
            gameController.SetFightState(FightState.Fight_Failture);
        };
        enemyController.OnEnemydead += () =>
        {
            module.LoadPanel<WinPanel>();
            gameController.SetFightState(FightState.Fight_Win);
        };


        //Debug.Log("Fight Enter");
    }

    public override void OnExit()
    {
        base.OnExit();
        // Debug.Log("Fight Exit");
    }
}
